package General;

import giny.model.Node;

import java.util.ArrayList;

import cytoscape.CyNetwork;

public class AdjacencyMatrix {
	private byte mat[][]; 
	private int n;
	
	public AdjacencyMatrix(int n)
	{
		mat= new byte[n][n];
		
		this.n=n;
		for (int i=0; i<n; i++)
			mat[i][i]=1;
		// do many stuff
	}
	
	public AdjacencyMatrix(CyNetwork graph, ArrayList<Node> nodes)
	{
		n=nodes.size();
		mat= new byte[n][n];
		for (int i=0; i<n; i++)
			mat[i][i]=1;
		
		for (int i=0; i<n; i++)
			for (int j=0; j<i; j++)
			{
				if (graph.isNeighbor(nodes.get(i), nodes.get(j)))
					set(i,j,(byte)1);
			}
		
		
	}
	
	public byte get (int i, int j)
	{
		return mat[i][j];
	}
	
	public void set (int i, int j, byte value)
	{
		 mat[i][j]=value;
		 mat[j][i]=value;
	}
	
	public byte[] getVector(int u)
	{
		byte[] vec= new byte[n];
		for (int i=0; i<n; i++)
			vec[i]=mat[u][i];
		vec[u]=1;
		return vec;
	}
	
	public int getSize()
	{
		return n;
	}
	
	public void print()
	{
		for (int i=0; i<n; i++)
		{
			System.out.println();
			for (int j=0; j<n; j++)
				System.out.print(mat[i][j] + " ");
		}
	}
	
	public String toString()
	{
		String s="\n";
		for (int i=0; i<n; i++)
		{
			for (int j=0; j<n; j++)
				s+= mat[i][j] + " ";
			
			s+="\n";
		}
		return s;
	}

}
